import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        ArrayIntegerStack intstack=new ArrayIntegerStack(n);
        intstack.create();
        for(int i=0;i<m;i++)
        {
            intstack.push(new Integer(sc.nextInt()));
            System.out.println(intstack.peek());
        }
        if(intstack.peek()!=null)
            System.out.println(intstack.peek().toString()+','+intstack.empty()+','+intstack.size());
        else
            System.out.println("null,"+intstack.empty()+','+intstack.size());
        System.out.println(Arrays.toString(intstack.getStack()));
        int x=sc.nextInt();
        for(int i=0;i<x;i++)
        {
            if(intstack.peek()==null)break;
            System.out.println(intstack.pop());
        }
        if(intstack.peek()!=null)
            System.out.println(intstack.peek().toString()+','+intstack.empty()+','+intstack.size());
        else
            System.out.println("null,"+intstack.empty()+','+intstack.size());
        System.out.println(Arrays.toString(intstack.getStack()));


    }
}


interface IntegerStack
{
    abstract Integer push(Integer item);
    abstract Integer pop();
    abstract Integer peek();
    abstract boolean empty();
    abstract int size();
}

class ArrayIntegerStack implements IntegerStack
{
    private int length;
    private static int index=0;
    private Integer[] stack=new Integer[10];

    public ArrayIntegerStack(int length) {
        this.length = length;

    }

    public void create()
    {
        Integer[] stack1=new Integer[this.length];
        stack=stack1;
    }

    @Override
    public String toString() {
        return "ArrayIntegerStack{" +
                "stack=" + Arrays.toString(stack) +
                '}';
    }

    public Integer[] getStack() {
        return stack;
    }

    public Integer push(Integer item)
    {
        if(item==null)return null;
        else if(index==length)return null;
        else
        {
            this.stack[index++]=item;
            return index;
        }
    }

    public Integer pop()
    {
        if(index==0)return null;
        else return stack[--index];
    }

    public Integer peek()
    {
        if(index==0)return null;
        else return stack[index-1];
    }

    public boolean empty()
    {
        if(index==0)return true;
        else return false;
    }

    public int size()
    {
        return index;
    }

}